package com.example.cglib.service;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * ClassName:TimerMethodInterceptor
 * Package:com.example.cglib.service
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/5/10-16:53
 * @Version:v1.0
 */
public class TimerMethodInterceptor implements MethodInterceptor {
    @Override
    public Object intercept(Object target, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        long begin = System.currentTimeMillis();
        //调用目标对象的目标方法
        Object invokeSuper = methodProxy.invokeSuper(target, objects);

        long end = System.currentTimeMillis();

        System.out.println("耗时" + (end - begin) + "毫秒");
        return invokeSuper;
    }
}
